<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>oneOf</title>
    <link rel="stylesheet" id="theme-link" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" id="iconlib-link" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css">
    <script src="../../dist/jsoneditor.js"></script>
</head>
<body>

<div class="container">
    <h1>Test</h1>
    <label for="value">value</label>
    <textarea id="value" class="value form-control" rows="10"></textarea>
    <button class='get-value'>Get Value</button>
    <button class='set-value'>Set Value</button>
    <div class='json-editor-container'></div>
</div>


<script>
  var jsonEditorContainer = document.querySelector('.json-editor-container');
  var value = document.querySelector('.value');

  var schema = {
    "type": "object",
    "properties": {
      "p4": {
        "type": "string",
        "minLength": 4
      },
      "p5": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "p1": {
                "type": "string",
                "minLength": 4
              },
              "p2": {
                "type": "string",
                "minLength": 4
              }
            },
            "required": [
              "p1",
              "p2"
            ]
          },
          {
            "type": "object",
            "properties": {
              "p3": {
                "type": "number"
              }
            },
            "required": [
              "p3"
            ]
          }
        ],
        "options": {
          "keep_oneof_values": false
        }
      }
    },
    "required": [
      "p4",
      "p5"
    ]
  }

  var editor = new JSONEditor(jsonEditorContainer, {
    schema: schema,
    theme: 'bootstrap4',
    show_errors: 'always',
    iconlib: 'fontawesome5',
    object_layout: 'normal',
    disable_collapse: true,
    disable_edit_json: true,
    disable_properties: true,
    use_default_values: false,
    required_by_default: true,
    disable_array_reorder: true,
    disable_array_delete_all_rows: true,
    disable_array_delete_last_row: true,
    keep_oneof_values: false,
    no_additional_properties: true
  });

  document.querySelector('.get-value').addEventListener('click', function () {
    value.value = JSON.stringify(editor.getValue());
    console.log(editor.getValue());
  });

  document.querySelector('.set-value').addEventListener('click', function () {
    editor.setValue({number_range: 2})
  });

</script>

</body>
</html>
